The EXIT WHEN
syntax can exit a loop depending on a condition. It should be preferred to the more verbose and error-prone IF ...
THEN EXIT; END IF;
syntax.
Noncompliant code example
SET SERVEROUTPUT ON
DECLARE
i PLS_INTEGER;
BEGIN
i := 0;
LOOP
IF i > 10 THEN -- Noncompliant
EXIT;
END IF;
DBMS_OUTPUT.PUT_LINE('i = ' || i);
i := i + 1;
END LOOP;
END;
/
Compliant solution
SET SERVEROUTPUT ON
DECLARE
i PLS_INTEGER;
BEGIN
i := 0;
LOOP
EXIT WHEN i > 10;
DBMS_OUTPUT.PUT_LINE('i = ' || i);
i := i + 1;
END LOOP;
END;
/